package com.xxx.ware.ware_manage_sys.controller.goods_cate;

import com.xxx.ware.ware_manage_sys.bean.dto.*;
import com.xxx.ware.ware_manage_sys.bean.vo.GoodsCateVo;
import com.xxx.ware.ware_manage_sys.bean.vo.ResultVo;
import com.xxx.ware.ware_manage_sys.bean.vo.WsDetailVo;
import com.xxx.ware.ware_manage_sys.service.IWmsGoodsCategoryService;
import com.xxx.ware.ware_manage_sys.service.IWsDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "仓库物品分类模块")
@RestController
@RequestMapping("/wms/goodscate")
@MapperScan("com.xxx.ware.ware_manage_sys.mapper")
@Slf4j
public class GoodsCateController {
    @Autowired
    private IWmsGoodsCategoryService wmsGoodsCategoryService;

    @PostMapping("/list")
    @ApiOperation(value = "物品种类列表", notes = "物品种类列表", httpMethod = "POST")
    private ResultVo<WebResultDto<GoodsCateVo>> list(@RequestBody GoodsCateQueryDto goodsCateQueryDto){
        try {
            return ResultVo.data(wmsGoodsCategoryService.getGoodsCateList(goodsCateQueryDto));
        } catch (Exception e) {
            log.error("查询物品种类列表失败，对应失败原因：" + e);
            return ResultVo.fail("查询物品种类列表失败");
        }
    }

    @PostMapping("/save")
    @ApiOperation(value = "添加种类", notes = "添加种类", httpMethod = "POST")
    public ResultVo<Boolean> save(@RequestBody @Validated GoodsCateUpdateSaveDto goodsCateUpdateSaveDto){
        try {
            return ResultVo.data(wmsGoodsCategoryService.saveGoodsCate(goodsCateUpdateSaveDto));
        } catch (Exception e) {
            log.error("添加物品种类失败，对应失败原因：" + e);
            return ResultVo.fail("添加物品种类失败");
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新物品种类", notes = "更新物品种类", httpMethod = "POST")
    public ResultVo<Boolean> updateCate(@RequestBody @Validated GoodsCateUpdateSaveDto goodsCateUpdateSaveDto){
        try {
            return ResultVo.data(wmsGoodsCategoryService.updateGoodsCate(goodsCateUpdateSaveDto));
        } catch (Exception e) {
            log.error("更新物品种类信息失败，对应失败原因：" + e);
        }
        return ResultVo.fail("更新物品种类信息失败");
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除物品种类", notes = "删除物品种类", httpMethod = "POST")
    public ResultVo<Boolean> removeCate(@RequestParam("id") Long id){
        try {
            return ResultVo.data(wmsGoodsCategoryService.removeGoodsCate(id));
        } catch (Exception e) {
            log.error("删除物品种类失败，对应失败原因：" + e);
            return ResultVo.fail("删除物品种类失败");
        }
    }
}
